<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改约定书信息</title>
    {% load static %}
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/oksub.css">
    <script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
    <script src="/static/lib/layui/layui.js"></script>

    <link type="text/css" rel="stylesheet" href="/static/css/metroStyle.css">
    <link type="text/css" rel="stylesheet" href="/static/css/treeSelectStyle.css">
    <script src="/static/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery.ztree.all.js"></script>
    <script type="text/javascript" src="/static/js/treeSelect.2.0.js"></script>
    <script type="text/javascript" src="/static/js/xm-select.js"></script>
</head>
<body>
<div class="ok-body">
    <!--form表单-->
   <form class="layui-form layui-form-pane ok-form">
        <div class="layui-row layui-col-space10">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">约定书编码</label>
            <div class="layui-input-block">
                <input type="text" name="paper_code" id="paper_code" placeholder="请输入身份证号！" autocomplete="off" class="layui-input"
                       lay-verify="required" disabled>
                <input type="text" name="id" id="id" class="layui-input" style="display: none">
            </div>
        </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">客户名称<span style="color: red">*</span></label>
            <div class="layui-input-block" id="customer" name="customer">

                                    </div>
        </div>
        </div>
       <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">签订日期<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="date" id="date" lay-verify="required" placeholder="请选择签订日期"
                           autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">项目负责人<span style="color: red">*</span></label>
                <div class="layui-input-block" id="user" name="user">

                 </div>
        </div>
        </div>

       <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">业务类型<span style="color: red">*</span></label>
                <div class="layui-input-block" id="type" name="type">

                </div>
        </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">金额(元)<span style="color: red">*</span></label>
                 <div class="layui-input-block">
                     <input type="text" name="money" id="money" lay-verify="money|number" placeholder="请输入项目金额<元>"
                           autocomplete="off" class="layui-input">
                     </div>
        </div>
        </div>

       <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">合同主体<span style="color: red">*</span></label>
                <div class="layui-input-block" id="company" name="company">

                </div>
        </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">承做部门<span style="color: red">*</span></label>
                 <div class="layui-input-block" id="dept" name="dept">

                 </div>
        </div>
        </div>
       <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">出具报告<span style="color: red">*</span></label>
            <div class="layui-input-block" id="LAY-switch-check">
                <input type="checkbox" id="is_issue" name="is_issue" lay-skin="switch" lay-filter="switchTest"
                       lay-text="出具|不出具">
            </div>
            </div>
        </div>
       <div class="layui-form-item layui-form-text" style="padding-top: 10px;">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark_describe" id="remark_describe" placeholder="请输入备注内容/140个汉字" maxlength="255" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item" style="padding-top: 10px;">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="edit">立即提交</button>
                <button type="reset" id="close" class="layui-btn layui-btn-primary">关闭</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->

<script type='text/javascript'>
    var data1;
    function child(d) {
        data1 = d;
    layui.use(["form", "okUtils","jquery", "okLayer",'laydate'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var laydate = layui.laydate;
        var okUtils = layui.okUtils;
        var okLayer = layui.okLayer;
        okLoading.close();
        $('#id').val(data1.id);
        $('#paper_code').val(data1.paper_code);
        $('#paper_customer').val(data1.paper_customer);
        $('#money').val(data1.paper_money);
        $('#remark_describe').val(data1.remark_describe);

        laydate.render({
                elem: '#date',
                type:'date',
                value:new Date(data1.paper_date),
                trigger:'click'
            });
        // 监听switch状态

         if (data1.whether_issue == 0) {
            layui.jquery('input[name="is_issue"]').prop('checked', 'checked');
            layui.jquery('input[name="is_issue"]').next().addClass('layui-form-onswitch'); //开
        } else {
            layui.jquery('input[name="is_issue"]').prop('checked','');
            layui.jquery('input[name="is_issue"]').next().removeClass('layui-form-onswitch'); //关
        }
         form.on("switch(switchTest)", function (obj) {
            $(obj.elem).attr('type', 'hidden').val(this.checked ? 0 : 1);
            form.render();
        });

        // 这里得把switch的状态弄对，不然，如果他创建就停用，数据就传不过去了
        form.on("submit(edit)", function (data) {
            okUtils.ajax("/business/contracts_edit/" + data.field.id, "post", data.field, true).done(function (response) {
                okLayer.greenTickMsg(response.msg, function () {
                    parent.layui.table.reload('tableId');
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }).fail(function (error) {
                // 这里已经有提示了
            });
            return false;
        });
        $("#close").click(function () {
            let index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
            parent.layui.table.reload('tableId');
            parent.layer.close(index);
        });
    });
    var customer_data = data1.paper_customer_id
    var demo1 = xmSelect.render({
        el: '#customer',
        name:'customer',
        radio: true,
        tips: '选择一名客户，可搜索客户名称',
        filterable: true,
        paging: true,
        pageSize: 3,
        clickClose: true,
        layVerify: 'required',
        initValue:[customer_data],
        layVerType: 'msg',
        toolbar: {show: true},
        prop: {
            name: 'cus_audited_object',
            value: 'id',
        },
        data: []
    })
    $.ajax({
        url: "{% url 'business:customers_list1' %}",
        type: "GET",
        success: function (ret) {
            var node = ret;
            demo1.update({
                data: node.data,
                autoRow: true,
            })
        },
        error: function () {
        }
    })
    var initdata=data1.paper_manager_id;
    var demo5 = xmSelect.render({
        el: '#user',
        name:'user',
        radio: true,
        tips: '选择项目负责人！',
        clickClose: true,
        filterable: true,
        paging: true,
        pageSize: 3,
        initValue:[initdata],
        layVerify: 'required',
        layVerType: 'msg',
        prop: {
            name: 'showname',
            value: 'id',
        },
        toolbar: {show: false},
        data: []
    })
    $.ajax({
        url: "{% url 'users:users_list1' %}",
        type: "GET",
        success: function (ret) {
            var node = ret;
            demo5.update({
                data: node.data,
                autoRow: true,
                iconfont: {
                    parent: 'hidden',
                }
            })
        },
        error: function () {
        }
    });
    var typedata=data1.paper_type_id
    var demo3 = xmSelect.render({
        el: '#type',
        name:'type',
        radio: true,
        tips: '选择一种业务类型，可搜索业务类型！',
        filterable: true,
        clickClose: true,
        layVerify: 'required',
        layVerType: 'msg',
        initValue:[typedata],
        tree: {
            show: true,
            strict: true,
        },
        prop: {
            name: 'type_name',
            value: 'id',
        },
        toolbar: {show: true},
        data: []
    })
    $.ajax({
        url: "{% url 'business:type_list1' %}",
        type: "GET",
        success: function (ret) {
            var node = ret;
            demo3.update({
                data: node.data,
                autoRow: true,
                iconfont: {
                    parent: 'hidden',
                }
            })
        },
        error: function () {
        }
    });
    var company_id = data1.paper_company_id
    var demo2 = xmSelect.render({
        el: '#company',
        name:'company',
        radio: true,
        tips: '选择一名主体，可搜索主体名称',
        filterable: true,
        clickClose: true,
        layVerify: 'required',
        layVerType: 'msg',
        initValue:[company_id],
        toolbar: {show: true},
        data: [],
        prop: {
            name: 'dept_name',
            value: 'id',
        },
    })
    $.ajax({
        url: "{% url 'config:depts_list2' %}",
        type: "GET",
        success: function (ret) {
            var node = ret;
            demo2.update({
                data: node.data,
                autoRow: true,
            })
        },
        error: function () {
        }
    });

    var dept_id = data1.paper_dept_id
    var demo4 = xmSelect.render({
        el: '#dept',
        name:'dept',
        tips: '选择承做部门！',
        filterable: false,
        clickClose: false,
        layVerify: 'required',
        layVerType: 'msg',
        initValue:dept_id,
        tree: {
            show: true,
            strict: true,
        },
        prop: {
            name: 'dept_name',
            value: 'id',
        },
        toolbar: {show: true},
        data: []
    })
    $.ajax({
        url: "{% url 'config:depts_list1' %}",
        type: "GET",
        success: function (ret) {
            var node = ret;
            demo4.update({
                data: node.data,
                autoRow: true,
                iconfont: {
                    parent: 'hidden',
                }
            })
        },
        error: function () {
        }
    });
    };
</script>
</body>
</html>
